package com.zb;


import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.sql.DataSource;

@Data
@ConfigurationProperties(prefix = "biz.default.tenant")
public class TenantConfigurationProperties {

    private String jdbcUrl;

    private String username;

    private String password;

    private String driverClassName;

    /**
     * 获取租户库默认数据源
     */
    public DataSource getDefaultProfileDataSource() {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl(jdbcUrl);
        config.setUsername(username);
        config.setPassword(password);
        config.setDriverClassName(driverClassName);
        config.setConnectionTestQuery("SELECT 1");
        return new HikariDataSource(config);
    }

}
